package com.machine.dao.tree.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.machine.bean.Tree;
import com.machine.dao.tree.DaoTree;

@Component("treeDaoImpl")
@Transactional
public class TreeDaoImpl implements DaoTree{
	
	private SessionFactory sessionfactory;
	
	public SessionFactory getSessionfactory() {
		return sessionfactory;
	}

	@Resource
	public void setSessionfactory(SessionFactory sessionfactory) {
		this.sessionfactory = sessionfactory;
	}

	@Override
	public List<Tree> getBeans() {
		String hql= "from Tree tree";
		Session session = sessionfactory.getCurrentSession();
		
		Query query = session.createQuery(hql);
		List<Tree> list = query.list();
		if(list.size() > 0){
			return list;
		}
		return null;
	}
	
	
	
}
